package org.linlinjava.litemall.admin.web;

import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallBanner;
import org.linlinjava.litemall.db.service.LitemallBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/banner")
public class BannerController {
        @Autowired
        private LitemallBannerService bannerService;

        @GetMapping("/list")
        public Object list() {
            List<LitemallBanner> banners = bannerService.querryAllBanner();
            return ResponseUtil.ok(banners);
        }

        @PostMapping("/add")
        public Object add(@RequestBody LitemallBanner litemallBanner) {
            bannerService.add(litemallBanner);
            return ResponseUtil.ok(litemallBanner);
        }

        @PostMapping("/update")
        public Object update(@RequestBody LitemallBanner litemallBanner) {
            bannerService.update(litemallBanner);
            return ResponseUtil.ok(litemallBanner);
        }

        @GetMapping("/delete")
        public Object delete(Integer id) {
            bannerService.delete(id);
            return ResponseUtil.ok();
        }
    }
